package com.tanhua.model.vo;

import com.tanhua.model.mongo.Survey;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SurveyVo implements Serializable {

    private String id;        // 问卷编号
    private String name;    // 问卷名称
    private String cover;   // 封面

    private String level;   // 级别
    private Integer star;   // 星级

    private Integer isLock;     // 是否锁住 （0解锁，1锁住）
    private String reportId;    // 最新报告id

    private List<QuestionsVo> questions;     // 问题集合


    public static SurveyVo init(Survey survey, List<QuestionsVo> questions) {
        SurveyVo vo = new SurveyVo();
        vo.setId(survey.getSurveyId().toString());
        BeanUtils.copyProperties(survey, vo);
        for (QuestionsVo question : questions) {
            QuestionsVo questionsVo = new QuestionsVo();
            if(question != null){
                questionsVo.setId(question.getId());
                questionsVo.setQuestion(question.getQuestion());
            }
        }
        vo.questions = questions;
        return vo;
    }
}
